import {localCache} from "@/utils";
import router from "@/router";

const needAuthorizationNames = [
    "MyEdit",
    "MyAddress",
    "Payment"
]
export const setupGuard = () => {
    router.beforeEach((to, from) => {
        const token = localCache.getCache("token")
        if (to.path === "/my/enter") {
            if (token) {
                return "/home"
            }
        } else {
            const pathName = to.name
            if (needAuthorizationNames.includes(<string>pathName)) {
                if (!token) {
                    return "/my/enter?return=" + to.path
                }
            }
        }
    })
}
